1 module unde.games.dizzy.omega.animations.platform1;
2 
3 import derelict.opengl3.gl;
4 import std.conv;
5 import std.format;
6 import std.math;
7 import unde.games.collision_detector;
8 import unde.games.dizzy.omega.dizzy;
9 import unde.games.dizzy.omega.main;
10 import unde.games.object;
11 import unde.games.renderer;
12 import unde.global_state;
13 
14 class Platform1:StaticGameObject
15 {
16     this(MainGameObject root, float[3] coords)
17     {
18         frame = -1;
19         x = coords[0];
20         y = coords[1];
21         z = coords[2];
22         models["platform1"] = root.models["platform1"];
23         super(root);
24     }
25 
26     override void draw(GlobalState gs)
27     {
28         glPushMatrix();
29         if (frame < 0)
30         {
31             glTranslatef(x, y, z);
32             recursive_render(gs, models["platform1"]);
33         }
34         else
35         {
36             float f = root.frame - frame;
37             if (f < 100.0)
38             {
39                 glTranslatef(x + f/10.0, y + f/10.0, z);
40                 recursive_render(gs, models["platform1"]);
41             }
42         }
43         glPopMatrix();
44     }
45     
46     override bool tick(GlobalState gs)
47     {
48         DizzyOmega dz = cast(DizzyOmega) root;
49         if (frame < 0 && dz.star0.taken)
50         {
51             frame = root.frame;
52             dz.collision_objects["solid"]["Platform1"] = null;
53             dz.collision_objects["solid"].remove("Platform1");
54             reset_collision_cache();
55         }
56 
57         return true;
58     }
59 
60     override void load(string[string] s)
61     {
62         string p = "platform1";
63         if (p in s)
64             frame = s[p].to!(long);
65         else
66             frame = -1;
67 
68         DizzyOmega dz = cast(DizzyOmega) root;
69         if (frame < 0)
70         {
71             dz.collision_objects["solid"]["Platform1"] = 
72                 dz.collision_objects["temp-solid"]["Platform1"];
73             reset_collision_cache();
74         }
75         else
76         {
77             dz.collision_objects["solid"]["Platform1"] = null;
78             dz.collision_objects["solid"].remove("Platform1");
79             reset_collision_cache();
80         }
81     }
82 
83     override void save(ref string[string] s)
84     {
85         if (frame >= 0)
86         {
87             string p = "platform1";
88             s[p] = frame.to!(string);
89         }
90     }                    
91 }